package cn.com.http.httpheader;

import java.util.ArrayList;
import java.util.List;


public class HttpHeaderList {
	private final List<HttpHeader> list = new ArrayList<HttpHeader>();

	public int getSize() {
		return list.size();
	}

	public void clear() {
		list.clear();
	}

	public HttpHeader getHeader(int index) {
		return list.get(index);
	}

	public void addHeader(HttpHeader header) {
		if (header == null)
			throw new NullPointerException();
		list.add(header);
	}

	public void remove(int index) {
		list.remove(index);
	}

	public HttpHeader removeHeader(String name) {
		if (name == null)
			throw new NullPointerException();
		int index = indexOf(name);
		if (index == -1)
			return null;
		return list.remove(index);
	}

	public int indexOf(String name) {
		for (int i = 0; i < list.size(); i++) {
			if (list.get(i).hasName(name)) {
				return i;
			}
		}
		return -1;
	}
}
